package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {

    public String[] suits = { "♠","♥","♣","◆"};
    List<Card> cards = new ArrayList<>();
    //买一副牌（设置好52张牌）
    public List<Card> setCards() {
        for(int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                Card card = new Card(suits[i], j);
                cards.add(card);
            }
        }
        return cards;
    }

    //洗牌
    public void wishCards() {
        for(int i = cards.size() - 1; i > 0; i--) {
            Random random = new Random();
            int value = random.nextInt(i);
            //交换
            Swap(cards ,value, i);
        }
    }

    public void Swap(List<Card> cards, int a, int b) {
        Card tmp = cards.get(a);
        cards.set(a, cards.get(b));
        cards.set(b, tmp);
    }

    //揭牌（一共有三人，每一个一次从最上面摸一张，一共摸五张）
    public void getCards() {
        List<List<Card>> hands = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        for(int i = 0; i < 5; i++) {
            for (int j = 0; j < hands.size(); j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个人摸的牌为：");
        System.out.println(hand1);

        System.out.println("第二个人摸的牌为：");
        System.out.println(hand2);

        System.out.println("第三个人摸的牌为：");
        System.out.println(hand3);

    }
}
